package com.thwcompany.controller;

import com.thwcompany.service.BusinessSendService;
import com.thwcompany.service.ProducerMessageConfimService;
import com.thwcompany.service.ReturnConfirmMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.UnsupportedEncodingException;

/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/03/26  16:05
 * @Description:
 */
@Controller
@SuppressWarnings("all")
public class HtmlController {
    @Autowired
    BusinessSendService businessSendService;
    @Autowired
    ProducerMessageConfimService producerMessageConfimService;
    @Autowired
    ReturnConfirmMessageService returnConfirmMessageService;

    @GetMapping(path = "/demo")
    @ResponseBody
    public ModelAndView  accessHtml(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("demo");
        modelAndView.addObject("user","thw");
        return modelAndView;
    }
    //测试死信队列
    @GetMapping(path = "/test1")
    @ResponseBody
    public  String  test1() {
        String routingKey = "business1";
        String message = "message: rabbitMQ dead letter demo... ";
        businessSendService.send(routingKey, message);
        return message;
    }
    //生产者消息确认机制
    @GetMapping(path = "/test2")
    @ResponseBody
    public  Object  test2() throws UnsupportedEncodingException {
        String exchange = "direct-pmc-exchange";
        String routingKey = "tenghw123";
        String message = "message: rabbitMQ 生产者消息确认机制... ";
        producerMessageConfimService.sendMessage1(exchange,routingKey,message);
        return message;
    }
    //测试return消息确认机制
    @GetMapping(path = "/test3")
    @ResponseBody
    public  Object  test3() {
        String exchange = "direct-pmc-exchange";
        String routingKey = "tenghw123";
        Object message = "message: rabbitMQ return消息确认机制... ";
        returnConfirmMessageService.sendMessage(exchange,routingKey,message);
        return message;
    }

}
